<script lang="ts" setup>
import { ref } from 'vue'
import { Search, Plus } from '@element-plus/icons-vue'
import http from '@/http'
import { ElMessage } from 'element-plus';
import { el } from 'element-plus/es/locale';

const displayStatus = ref(false);

//病例ID
const chId = ref('')
//检查项目
const inspectionItemsValue = ref('')
const inspectionItems = [
  '乙肝五项',
  '血常规',
  'CT',
  'X光'
]

//获取

function checkInspectionItems(val: any) {
  inspectionItemsValue.value = val;
}

//信息
const information = ref({
  patientId: '',
  itemName: '',
  patientName: '',
  remark: '',
  itemId:'',
  price:'',
})


//查询检查信息
function queryAndCheckInformatio() {
  http.get('/hisCareOrde/queryAndCheckInformatio?id=' + chId.value)
    .then((res) => {
      if (res != "") {
        const coId = res.coId;
        information.value.patientId = res.patientId;
        information.value.patientName = res.patientName;
        http.get('/hco/queryAndCheckInformatio', {
          params: {
            itemName: inspectionItemsValue.value,
            itemId: coId
          }
        })
          .then((res) => {
            if (res != "") {
              information.value.itemName = res.itemName;
              information.value.remark = res.remark;
              information.value.itemId = res.itemId;
              information.value.price = res.price;
              displayStatus.value = true;
            }
          })
      }
    })
}

const itemId = ref(false);

//检查结果表数据
const hisCheckResult = ref({
  itemId:'',
  checkItemName:'',
  price:'',
  patientId:'',
  patientName:'',
  resultStatus:0
})
//开始检测
function startDetection() {
  hisCheckResult.value.itemId = information.value.itemId;
  hisCheckResult.value.checkItemName = inspectionItemsValue.value
  hisCheckResult.value.price = information.value.price;
  hisCheckResult.value.patientName = information.value.patientName;
  hisCheckResult.value.patientId = information.value.patientId;
  http.post('/hcr/addHisCheckResult',hisCheckResult.value)
  .then((res) => {
    if (res == 1) {
      ElMessage({
        message: '开始成功',
        type: 'success',
      })
      displayStatus.value = false;
      itemId.value=true;
    }
  })
}
</script>
<template>
  <el-row>
    <el-col :span="24">
      <span>检查项目：</span><el-segmented v-model="inspectionItemsValue" :options="inspectionItems"
        @change="checkInspectionItems" style="width: 400px;" />
    </el-col>
  </el-row>
  <br>
  <el-row>
    <el-col :span="24">
      <span>病例ID：</span><el-input v-model="chId" style="width: 240px" />&nbsp;<el-button type="primary" :icon="Search"
        @click="queryAndCheckInformatio">查询</el-button>
    </el-col>
  </el-row>
  <div v-if="displayStatus">
    <el-row>
      <el-col :span="4">
        <p><span>患者编号：</span></p>
        <p><span>检查项目：</span></p>
      </el-col>
      <el-col :span="4">
        <p><span>{{ information.patientId }}</span></p>
        <p><span>{{ information.itemName }}</span></p>
      </el-col>
      <el-col :span="4">
        <div class="grid-content ep-bg-purple" />
      </el-col>
      <el-col :span="4">
        <div class="grid-content ep-bg-purple-light" />
      </el-col>
      <el-col :span="4">
        <p><span>患者姓名：</span></p>
        <p><span>检查备注：</span></p>
      </el-col>
      <el-col :span="4">
        <p><span>{{ information.patientName }}</span></p>
        <p><span>{{ information.remark }}</span></p>
      </el-col>
    </el-row>
    <el-col :span="24">
      <el-button type="primary" :icon="Plus" style="width: 100%;" @click="startDetection">开始检测</el-button>
    </el-col>
  </div>
  <div style="width: 300px; margin: auto;" v-else>暂无数据</div>
  <div v-if="itemId">
    检查ID：{{information.itemId}}
  </div>
</template>
<style scoped></style>
